<!DOCTYPE html>
<html>
{include file="public/head"}

<body style="margin-top: 0px;">
    <!-- 分割 -->
    <div class="layui-container" style="max-width:600px;max-height: 500px;">
        <div class="fly-panel fly-panel-user" pad20="">
            <div class="layui-tab layui-tab-brief" lay-filter="user">
                <ul class="layui-tab-title">
                    <li class="layui-this">登入</li>
                    <li><a href="{:url('user/userregister')}">注册</a></li>
                </ul>
                <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-form layui-form-pane">
                            <form method="post" action="{:url('user/tologin')}" id="myform">
                                <div class="layui-form-item">
                                    <label for="L_email" class="layui-form-label">用户名</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="email" name="email" required="" placeholder="用户名或者邮箱" lay-verify="*" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label for="L_pass" class="layui-form-label">密码</label>
                                    <div class="layui-input-inline">
                                        <input type="password" id="password" name="password" required="" lay-verify="required" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <button class="layui-btn" lay-filter="login" lay-submit>立即登录</button>

                                    <span style="padding-left:20px;"> <a href="{:url('user/forget')}">忘记密码？</a> 
                                    </span> 
                                    {if condition="isset($qq_login)"}
                                        <a href="#" style='color: #2894FF;' onclick="layer.msg('正在通过QQ登入', {icon:16, shade: 0.1, time:0})" title="QQ登入" id='qq_login' class="iconfont icon-qq"></a>
                                    {/if}
                                </div>

                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 分割 -->
</body>
<script>
layui.use(['form', 'jquery'], function() {
    var form = layui.form;
    var $ = layui.jquery;

    //监听提交 
    form.on('submit(login)', function(data) {
        // layer.msg(JSON.stringify(data.field));
        console.log(data.field); //当前容器的全部表单字段，名值对形式：{name: value}
        $.ajax({
            url: "{:url('user/judgelogin')}",
            type: 'post',
            data: data.field,
            dataType: "JSON",
            success: function(res) {
                if (res['result'] == true) {
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    layer.msg('登录成功~');
                    setTimeout("parent.location.reload()",1000);
                    // parent.layer.close(index);
                } else {
                    $(".layui-input").blur();
                    layer.msg('账号或密码输入错误');
                }
            },
            error: function() {
                layer.msg('页面进入后台失败');
            }
        });
        return false;
    });
    
    // qq登录
    $('#qq_login').click(function(){
        var url='{:url('web/QQconnect/qq_login')}';
        parent.location.href=url;
    });
});
</script>

</html>